<?php
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/shared/db_connection.php';

function load_category_by_id($journal_id){
    $con = open_connect();
    //run the store proc
    $result = mysqli_query($con, "CALL GetAllCategoriesByJournalID(".$journal_id.")")
            or die("Query fail: " . mysqli_error());

    $list = array();
    $count = 0;
    while ($row = mysqli_fetch_array($result)) {
        $item = array();
        $item["CategoryID"] = $row['CategoryID'];
        $item["Title"] = $row['Title'];
        $item["Description"] = $row['Description'];
        $item["JournalID"] = $row['JournalID'];
        $item["JournalTitle"] = $row['JournalTitle'];
        $list[$count] = $item;
        $count = $count + 1;
    }

    close_connect($con);
    return $list;
}

